<template>
	<view>
		<view class=" u-p-r-30 u-p-l-30">
			<view class="content wrap">
				<u-form>
					<u-form-item label="预约日期" label-width="170" left-icon="calendar"><u-input v-model="arriveTime" placeholder="选择日期" type="select" @click="getT3()"/></u-form-item>
				</u-form>
			</view>
		</view>
		<u-card padding="16" v-for="(item,index) in dataList" :key="index">
			<view class="" slot="head">
				<view class="wrap">
					<u-row>
						<u-col span="9" text-align="left">
							<view class="u-line-1 weikaishi2">
								<span>月台：{{item.railwayPlatformName}}</span>
							</view>
						</u-col>
						<u-col span="3" text-align="right" v-if="item.state == '空闲'">
							<view class="u-line-1 weikaishi3 yiwancheng">
								<span>空闲</span>
							</view>
						</u-col>
					</u-row>
				</view>
			</view>
			<view class="" slot="body">
				<view class="wrap">
					<u-row v-for="(item1,index1) in item.list" :key="index1">
						<u-col span="9" text-align="left" v-if="item1.makeType == '提货预约'">
							<view class="u-line-1 u-m-t-2 weikaishi3 lanse">
								<span>预约类型：{{item1.makeType}}</span>
							</view>
						</u-col>
						<u-col span="9" text-align="left" v-else>
							<view class="u-line-1 u-m-t-2 weikaishi3 jinxingzhong">
								<span>预约类型：{{item1.makeType}}</span>
							</view>
						</u-col>
						<u-col span="3" text-align="right" v-if="item1.state == '进行中'">
							<view class="u-line-1 weikaishi3 jinxingzhong">
								<span>{{item1.state}}</span>
							</view>
						</u-col>
						<u-col span="3" text-align="right" v-else-if="item1.state == '已完成'">
							<view class="u-line-1 weikaishi3 yiwancheng">
								<span>{{item1.state}}</span>
							</view>
						</u-col>
						<u-col span="3" text-align="right" v-else>
							<view class="u-line-1 weikaishi3">
								<span>{{item1.state}}</span>
							</view>
						</u-col>
						<u-col span="6" text-align="left">
							<view class="u-line-1 weikaishi u-m-t-2">
								<span>编号：{{item1.v2}}</span>
							</view>
						</u-col>
						<u-col span="6" text-align="right">
							<view class="u-line-1 weikaishi u-m-t-2">
								<span>来源地：{{item1.v1}}</span>
							</view>
						</u-col>
						<u-col span="6" text-align="left">
							<view class="u-line-1 weikaishi u-m-t-2">
								<span>车牌号：{{item1.carNumber}}</span>
							</view>
						</u-col>
						<u-col span="6" text-align="right">
							<view class="u-line-1 u-m-t-2" @click="badaphone(item1.tel)">
								<u-icon name="phone" :label="item1.driver" label-color="#2b85e4" color="#2b85e4" size="30"></u-icon>
							</view>
						</u-col>
						<u-col span="6" text-align="left">
							<view class="u-line-1 u-m-t-2">
								<span>车型：{{item1.carType}}</span>
							</view>
						</u-col>
						<u-col span="6" text-align="left">
							<view class="u-line-1 u-m-t-2">
								<span>体积：{{item1.volume}}</span>
							</view>
						</u-col>
						<u-col span="12" text-align="left">
							<view class="u-line-1 u-m-t-2">
								<span>抵达时间：{{item1.arriveTime}}</span>
							</view>
						</u-col>
						<u-col span="12" text-align="left">
							<view class="u-line-1 u-m-t-2">
								<span>离开时间：{{item1.leaveTime}}</span>
							</view>
						</u-col>
						<u-col span="12" text-align="left">
							<view class="u-line-1 u-m-t-2">
								<span>备注：{{item1.notes}}</span>
							</view>
						</u-col>
						<u-col span="12" text-align="left">
							<view class="u-line-1 u-m-t-2 ">
								<span>审核备注：</span><span class="yizuofei">{{item1.examineNotes}}</span>
							</view>
						</u-col>
						<u-col span="6" text-align="right" v-if="item1.state == '已预约' || item1.state == '已修改'">
							<view class="u-m-t-10">
								<span><u-button type="primary" size="default" @click="totask(item1.id)">审核</u-button></span>
							</view>
						</u-col>
						<u-col span="6" text-align="right" v-if="item1.state == '已预约' || item1.state == '已修改'">
							<view class="u-m-t-10">
								<span><u-button type="default" size="default" @click="putchang(item1.id)">入场</u-button></span>
							</view>
						</u-col>
						<u-col span="6" text-align="right" v-if="item1.state == '进行中'">
							<view class="u-m-t-10">
								<span><u-button type="success" size="default" @click="over(item1.id)">完成</u-button></span>
							</view>
						</u-col>
						<u-col span="12" text-align="right" >
							<view class="u-m-t-25 u-line-1">
							</view>
						</u-col>
					</u-row>
				</view>
			</view>
		</u-card>
		<view>
			<u-calendar v-model="show3" mode="date" max-date="2070-01-01" @change="change"></u-calendar>
		</view>
		<view>
			<u-toast ref="uToast" />
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				flex:'',
				pageNo: 1,
				hasMore: true,
				orderCount: 0,
				dataList: [],
				show3:false,
				arriveTime:'',
			}
		},
		onLoad(open) {
			//#ifdef H5 || APP-PLUS
			this.flex = 'u-flex'
			//#endif
			
			let year = new Date().getFullYear();//年
			let month = new Date().getMonth() + 1;//注意！月份是从0月开始获取的，所以要+1;
			let day = new Date().getDate();//日
			this.arriveTime =  year + '-' + (month >= 10 ? month : '0' + month) + '-' + (day >= 10 ? day : '0' + day);
				
			this.refresh()
		},
		onShow() {
			this.refresh()
		},
		onPullDownRefresh() {
			this.refresh()
			uni.stopPullDownRefresh()
		},
		methods: {
			putchang(id){
				uni.showModal({
					content: '确定入场吗？',
					success: (res) => {
						if (res.confirm) {
							uni.showLoading({
								title: '正在提交'
							})
							this.$http.post('/rest/railwayPlatform/editstate',{
							},{
								params: {
									id:id,
									state:'进行中'
								},
								header: {
									'Authorization' :uni.getStorageSync('token'),
								}
							}).then(res => {
								uni.hideLoading()
								if(res.data.code == 200) {
									this.refresh()
									this.$refs.uToast.show({
										title: '操作成功',
										type: 'success'
									})
								} else {
									this.$refs.uToast.show({
										title: res.data.message,
										type: 'error'
									})
								}
							})
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				})
			},
			over(id){
				uni.showModal({
					content: '确定完成吗？',
					success: (res) => {
						if (res.confirm) {
							uni.showLoading({
								title: '正在提交'
							})
							this.$http.post('/rest/railwayPlatform/editstate',{
							},{
								params: {
									id:id,
									state:'已完成'
								},
								header: {
									'Authorization' :uni.getStorageSync('token'),
								}
							}).then(res => {
								uni.hideLoading()
								if(res.data.code == 200) {
									this.refresh()
									this.$refs.uToast.show({
										title: '操作成功',
										type: 'success'
									})
								} else {
									this.$refs.uToast.show({
										title: res.data.message,
										type: 'error'
									})
								}
							})
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				})
			},
			totask(id){
				this.$Router.push({ 
					name: 'make_update',
					params: { yid:id },
				})
			},
			badaphone(tel){
				uni.makePhoneCall({
				    phoneNumber: tel
				});
			},
			change(e) {
				this.arriveTime = e.result
				this.refresh()
			},
			getT3(){
				this.show3 = true
			},
			refresh(){
				uni.showLoading({
					title: '加载中...'
				})
				this.$http.post('/rest/railwayPlatform/yilist',{
				},{
					params: {arriveTime:this.arriveTime},
					header: {
						'Authorization' :uni.getStorageSync('token'),
					}
				}).then(res => {
					uni.hideLoading()
					this.dataList = res.data.data
				})
			},
		},
	}
</script>

<style>

</style>
